package com.ylsf.blog.controller;

import com.ylsf.blog.pojo.Article;
import com.ylsf.blog.service.EditService;
import com.ylsf.blog.service.impl.EditServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * 编辑控制类
 */
@WebServlet("/edit")
public class EditServlet extends HttpServlet {
    private EditService editService=new EditServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        //获取文章标题
        String title = request.getParameter("title");
        //获取文章内容
        String context = request.getParameter("context");
        //获取文章作者
        String author = request.getParameter("author");
        //获取文章发布时间
        String date = request.getParameter("date");
        Date date1 = new Date(date);
        Article article=new Article(title,context,date1,author);
        //发布文章
        Integer integer = editService.publishArticle(article);
        response.getWriter().print("{\"yn\":"+integer+"}");
    }
}
